import { login } from '@/api/user'
import { setToken, getToken } from '@/utils/auth'

export default {
  namespaced: true,
  actions: {
    async postToken(context, val) {
      const res = await login(val)
      context.commit('UPDATETOKEN', res.data)
      return res
    }
  },
  mutations: {
    UPDATETOKEN(state, token) {
      state.token = token
      setToken(token)
    }
  },
  state: {
    token: getToken() || ''
  },
  getters: {}
}
